/*
  Copyright (C) 2023. Huawei Technologies Co., Ltd. All rights reserved.
  
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
*/
#ifndef __CTC_ERROR_H__
#define __CTC_ERROR_H__


typedef enum en_errno {
  CT_SUCCESS = 0,
  ERR_ALLOC_MEMORY = 1,
  ERR_CAPABILITY_NOT_SUPPORT = 101,
  ERR_OPERATIONS_NOT_SUPPORT = 130,
  ERR_GENERIC_INTERNAL_ERROR = 299,
  ERR_TOO_MANY_CONNECTIONS = 403,
  ERR_NOT_SUPPORT = 404,
  ERR_ROW_LOCKED_NOWAIT = 408,
  ERR_USER_DDL_LOCKED = 411,
  ERR_CLT_PARALLEL_LOCK = 517,
  ERR_SQL_SYNTAX_ERROR = 601,
  ERR_COLUMNS_MISMATCH = 619,
  ERR_INVALID_SESSION_ID = 683,
  ERR_MAX_ROLE_COUNT = 686,
  ERR_TOO_MANY_OBJECTS = 706,
  ERR_COLUMN_HAS_NULL = 709,
  ERR_SNAPSHOT_TOO_OLD = 715,
  ERR_DEAD_LOCK = 716,
  ERR_LOCK_TIMEOUT = 717,
  ERR_OPERATION_CANCELED = 718,
  ERR_DC_INVALIDATED = 722,
  ERR_RECORD_SIZE_OVERFLOW = 727,
  ERR_DUPLICATE_KEY = 729,
  ERR_DEF_CHANGED = 732,
  ERR_SERIALIZE_ACCESS = 735,
  ERR_SAVEPOINT_NOT_EXIST = 736,
  ERR_TOO_MANY_SAVEPOINTS = 737,
  ERR_NO_MORE_LOCKS = 740,
  ERR_NAME_TOO_LONG = 748,
  ERR_OBJECT_EXISTS = 753,
  ERR_INDEX_INVALID = 759,
  ERR_FILE_NOT_EXIST = 771,
  ERR_DATABASE_ROLE = 773,
  ERR_SPACE_NOT_EXIST = 780,
  ERR_USER_NOT_EXIST = 781,
  ERR_SPACE_ALREADY_EXIST = 788,
  ERR_ROW_SELF_UPDATED = 814,
  ERR_COL_TYPE_MISMATCH = 817,
  ERR_BTREE_LEVEL_EXCEEDED = 820,
  ERR_TABLE_OR_VIEW_NOT_EXIST = 843,
  ERR_COLUMN_NOT_EXIST = 844,
  ERR_FUNCTION_NOT_EXIST = 845,
  ERR_TABLE_ID_NOT_EXIST = 846,
  ERR_DROP_CONS = 847,
  ERR_SEQ_NOT_EXIST = 848,
  ERR_OBJECT_ALREADY_DROPPED = 849,
  ERR_XA_EXTEND_BUFFER_EXCEEDED = 850,
  ERR_ALLOC_TEMP_EXTENT = 851,
  ERR_RECYCLE_PARTITION_NOT_EXIST = 852,
  ERR_PERMANENTOBJ_IN_TEMPSPACE = 853,
  ERR_BACKUP_RESTORE = 855,
  ERR_CANNOT_MODIFY_COLUMN = 856,
  ERR_LOG_ARCH_DEST_IN_USE = 857,
  ERR_CANNOT_CLOSE_ARCHIVE = 858,
  ERR_OPEN_RESETLOGS = 859,
  ERR_LOGFILE_OPERATION_CANCELED = 860,
  ERR_SPACE_OPEARTION_CANCELED = 861,
  ERR_READMODE_OPEARTION_CANCELED = 862,
  ERR_RENAME_FUNC_INDEX = 863,
  ERR_ENFORCE_INDEX = 864,
  ERR_EXCEED_MAX_BACKUP_PATH_LEN = 865,
  ERR_NO_AUTO_INCREMENT_COLUMN = 866,
  ERR_DATABASE_IS_ROLLING_BACK = 867,
  ERR_TOO_MANY_TABLES = 868,
  ERR_CHECKSUM_FAILED = 869,
  ERR_NOLOGGING_SPACE = 870,
  ERR_MISUSE_UNDO_SPACE = 871,
  ERR_PART_LIST_COUNT = 872,
  ERR_USER_ID_NOT_EXIST = 873,
  ERR_EXCEED_MAX_INCR_BACKUP = 874,
  ERR_ALTER_DB_TIMEZONE_FAILED = 875,
  ERR_SHRINK_SPACE_SIZE = 876,
  ERR_CANNOT_OPEN_DATABASE = 877,
  ERR_SEND_RECORD_REQ_FAILED = 878,
  ERR_RECORD_BACKUP_FAILED = 879,
  ERR_PAGE_CORRUPTED = 880,
  ERR_DATAFILE_RESIZE_TOO_SMALL = 881,
  ERR_EXCLUDE_SPACES = 882,
  ERR_INDEX_ALREADY_DROPPED = 883,
  ERR_DATAFILE_RESIZE_EXCEED = 884,
  ERR_XA_IN_AUTON_TRANS = 885,
  ERR_SHRINK_EXTEND = 886,
  ERR_SPACE_NO_DATAFILE = 887,
  ERR_DUPLICATE_ENTRY = 970,

  ERR_ROW_IS_REFERENCED = 1123,
  ERR_CONSTRAINT_VIOLATED_NO_FOUND = 1128,
  ERR_EXCEED_MAX_CASCADE_DEPTH = 1133,
  ERR_CHILD_ROW_CANNOT_ADD_OR_UPDATE = 1134,

  /* additional: sql engine */
  ERR_DUPLICATE_AUTO_COLUMN = 1300,
  ERR_DUPLICATE_TABLE = 1301,
  ERR_UNKNOWN_LOB_TYPE = 1302,
  ERR_CONVERT_TYPE = 1303,
  ERR_UNSUPPORT_DATATYPE = 1304,
  ERR_UNKNOWN_PLAN_TYPE = 1305,
  ERR_INVALID_DATAFILE_NUMBER = 1306,
  ERR_STORED_PROCEDURE = 1307,
  ERR_FEW_FILLED = 1308,
  ERR_DISTRI_COLUMN_DATA_TYPE = 1309,
  ERR_COMMENT_OBJECT_TYPE = 1310,
  ERR_MUST_BE_FIX_DATATYPE = 1311,
  ERR_KEY_EXPECTED = 1312,
  ERR_INVALID_ATTR_NAME = 1313,
  ERR_ONLY_SUPPORT_STR = 1314,
  ERR_COMPARE_TYPE = 1315,
  ERR_UNEXPECTED_KEY = 1316,
  ERR_UNEXPECTED_ARRG = 1317,
  ERR_UNKNOWN_DATATYPE = 1318,
  ERR_NUM_OVERFLOW = 1319,
  ERR_UNDEFINED_OPER = 1320,
  ERR_UNKNOWN_ARRG_OPER = 1321,
  ERR_CALC_EXPRESSION = 1322,
  ERR_UNSUPPORT_FUNC = 1323,
  ERR_INVOKE_FUNC_FAIL = 1324,
  ERR_COLUMN_DATA_TYPE = 1325,
  ERR_CAST_TO_COLUMN = 1326,
  ERR_UNSUPPORT_OPER_TYPE = 1327,
  ERR_TOO_MANY_ARRG = 1328,
  ERR_INVALID_FUNC = 1329,
  ERR_PARAM_VALUE_OUT_RANGE = 1330,
  ERR_INVALID_PACKAGE = 1331,
  ERR_FORBID_CREATE_SYS_USER = 1332,
  ERR_NO_OPTION_SPECIFIED = 1333,
  ERR_XA_TRANS_EXEC = 1334,
  ERR_READ_LOB_NULL = 1335,
  ERR_DATANODE_EXIST = 1336,
  ERR_DATANODE_NOT_EXIST = 1337,
  ERR_COORDNODE_FORBIDDEN = 1338,
  ERR_DISTRI_COLUMN_FORBIDDEN = 1339,
  ERR_INVALID_SEL4UPDATE = 1340,
  ERR_NO_SORT_ITEM_REMOTE = 1341,
  ERR_COLUM_LIST_EXCEED = 1342,
  ERR_INVALID_PROTOCOL_INVOKE = 1343,
  ERR_INVALID_STATEMENT_ID = 1344,
  ERR_DML_INSIDE_QUERY = 1345,
  ERR_EXCEED_MAX_FIELD_LEN = 1346,
  ERR_FUNCTION_NOT_INDEXABLE = 1347,
  ERR_RESERV_SQL_CURSORS_DECREASE = 1348,
  ERR_SELECT_ROWID = 1349,
  ERR_INVALID_NUMBER_FORAMT = 1350,
  ERR_INVALID_SESSION_TYPE = 1351,
  ERR_SQL_MAP_ONLY_SUPPORT_DML = 1352,
  ERR_SQL_MAP_NOT_EXIST = 1353,
  ERR_TF_ONLY_ONE_TABLE = 1354,
  ERR_TF_TABLE_NAME_NULL = 1355,
  ERR_EXCEED_MAX_STMTS = 1356,
  ERR_DEFAULT_LEN_TOO_LARGE = 1357,
  ERR_EXPECT_COLUMN_HERE = 1358,
  ERR_FOR_UPDATE_FROM_VIEW = 1359,
  ERR_CALC_COLUMN_NOT_ALLOWED = 1360,
  ERR_FOR_UPDATE_NOT_ALLOWED = 1361,
  ERR_INVALID_ARRAY_FORMAT = 1362,
  ERR_WRONG_ELEMENT_COUNT = 1363,
  ERR_INDEX_ON_ARRAY_FIELD = 1364,
  ERR_DATATYPE_NOT_SUPPORT_ARRAY = 1365,
  ERR_INVALID_ARG_TYPE = 1366,
  ERR_CONVERT_CODE_FAILED = 1367,
  ERR_REF_ON_ARRAY_COLUMN = 1368,
  ERR_SET_DEF_ARRAY_VAL = 1369,
  ERR_INVALID_SUBSCRIPT = 1370,
  ERR_USE_WRONG_SUBSCRIPT = 1371,
  ERR_ARRAY_NOT_SUPPORT = 1372,
  ERR_MODIFY_ARRAY_COLUMN = 1373,
  ERR_MODIFY_ARRAY_DATATYPE = 1374,
  ERR_WRONG_TABLE_TYPE = 1375,
  ERR_TF_DDL_ID_NULL = 1376,
  ERR_TF_DDL_INFO_NULL = 1377,
  ERR_TF_DDL_ID_OVER_LEN = 1378,
  ERR_TF_DDL_INFO_OVER_LEN = 1379,
  ERR_ARRAY_TO_STR_FAILED = 1380,
  ERR_AUTOINC_READ_FAILED = 1467,
  
  ERR_OAMAP_DUP_KEY_ERROR = 2008,
  ERR_OAMAP_INSERTION_FAILED = 2009,
  ERR_OAMAP_FETCH_FAILED = 2010,

  ERR_GSS_FILE_IS_OPEN = 2042,

  // SHM and CTC
  ERR_SEM_FAULT = 4000,
  ERR_BATCH_DATA_HANDLE_FAILED = 4001,
  ERR_SHM_SEND_MSG_FAILED = 4002,
  ERR_INSTANCE_REG_FAILED = 4003,
  ERR_CONNECTION_FAILED = 4004,

  ERR_USER_NOT_EMPTY_4MYSQL = 4005,
  ERR_FK_NO_INDEX_PAREN_4MYSQL = 4006,
  ERR_CHILD_DUPLICATE_KEY = 4007,
  ERR_WRITE_OPT_IN_READONLY = 4008,
  CTC_DDL_VERSION_NOT_MATCH = 9999,
} ct_errno_t;

#define convert_ctc_error_code_to_mysql(error) convert_ctc_error_code_to_mysql_impl(error, __func__, __LINE__)
int convert_ctc_error_code_to_mysql_impl(ct_errno_t error, const char* funcName, const int line);

void ctc_alter_table_handle_fault(ct_errno_t error);
#endif